{include file="common/head"/}
<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>{$title}</legend>
    </fieldset>
    <form class="layui-form layui-form-pane" lay-filter="form">
        <div class="layui-form-item">
            <label class="layui-form-label">{:lang('username')}</label>
            <div class="layui-input-block">
                <input type="text" name="username" lay-verify="required"  placeholder="{:lang('pleaseEnter')}登录用户名" class="layui-input" <?php if(!empty($info_raw['username']))echo 'readonly'; ?>>
                <tip>用户名在2到25个字符之间。（用户名请一次性确定，随意修改用户名将有可能造成用户名关联的数据无法关联）</tip>
            </div>

        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">真实姓名</label>
            <div class="layui-input-block">
                <input type="text" name="realname"   placeholder="请填写真实姓名" class="layui-input" >
            </div>

        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">所属用户组</label>
            <div class="layui-input-block">
                <?php
                $authGroup = \think\facade\Db::name('auth_group')->field('id,pid,title')->order('pid asc,id asc')->select();
                $nav = new \clt\Leftnav();
                $authGroupTree = $nav->menu($authGroup);
                ?>

                <select name="group_id" lay-verify="required">
                    <option value="">请选择用户组</option>
                    {volist name="authGroupTree" id="vo"}
                    <option value="{$vo.id}" <?php if(!empty($info_raw['group_id']) && $info_raw['group_id']==$vo['id'])echo 'selected'; ?>>{$vo.lefthtml}{$vo.title}</option>
                    {/volist}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">身份</label>
            <div class="layui-input-block">
                {foreach $AuthStandingList as $k=>$v}
                <input type="checkbox" name="standing_list[]" value="{$k}" title="{$v}" <?php if(!empty($info_raw['standing']) && in_array($k, $info_raw['standing_list']))echo 'checked'; ?> >
                {/foreach}
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">业绩月目标</label>
            <div class="layui-input-block">
                <input type="text" name="mubiao"   placeholder="月目标金额" class="layui-input">
            </div>
        </div>
        <!--
        <div class="layui-form-item">
            <label class="layui-form-label">提成点</label>
            <div class="layui-input-block">
                <input type="text" name="ticheng" lay-verify="required" placeholder="提成点" class="layui-input">
            </div>
        </div>
        -->

        <div class="layui-form-item">
            <label class="layui-form-label">{:lang('pwd')}</label>
            <div class="layui-input-block">
                <input type="password" name="pwd" placeholder="{:lang('pleaseEnter')}登录密码" {if condition="ACTION eq 'adminadd'"}lay-verify="required"{/if} class="layui-input">
                <tip>密码必须大于6位，小于15位。</tip>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">头像</label>
            <input type="hidden" name="avatar" id="avatar">
            <input type="hidden" name="admin_id" id="admin_id">
            <div class="layui-input-block">
                <div class="layui-upload">
                    <button type="button" class="layui-btn layui-btn-primary" id="adBtn"><i class="icon icon-upload3"></i>点击上传</button>
                    <div class="layui-upload-list">
                        <img class="layui-upload-img" id="adPic">
                        <p id="demoText"></p>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{:lang('email')}</label>
            <div class="layui-input-block">
                <input type="text" name="email" lay-verify="email" placeholder="{:lang('pleaseEnter')}用户邮箱" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                用于密码找回，请认真填写。
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">{:lang('tel')}</label>
            <div class="layui-input-block">
                <input type="text" name="tel" lay-verify="phone" value="" placeholder="{:lang('pleaseEnter')}手机号" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="submit">{:lang('submit')}</button>
            </div>
        </div>
    </form>
</div>
{include file="common/foot"/}
<script>
    layui.use(['form', 'layer','upload'], function () {
        var form = layui.form, layer = layui.layer,$= layui.jquery,upload = layui.upload;
        var info = {$info|raw};
        form.val("form", info);
        if(info){
            $('#adPic').attr('src',info.avatar);
        }
        form.render();
        form.on('submit(submit)', function (data) {
            loading =layer.load(1, {shade: [0.1,'#fff']});
            $.post("", data.field, function (res) {
                layer.close(loading);
                if (res.code > 0) {
                    layer.msg(res.msg, {time: 2800, icon: 1}, function () {
                        if(!info){
                            window.parent.location.reload();
                        }
                    });
                } else {
                    layer.msg(res.msg, {time: 2800, icon: 2});
                }
            });
        });
        //普通图片上传
        var uploadInst = upload.render({
            elem: '#adBtn'
            ,url: '{:url("ajax/upload")}'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#adPic').attr('src', result); //图片链接（base64）
                });
            },
            done: function(res){
                if(res.code>0){
                    $('#avatar').val(res.data.url);
                }else{
                    //如果上传失败
                    return layer.msg('上传失败');
                }
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });
    });
</script>
